/**
 * 联合类型
 */
function padLeft(value, padding) {
    if (typeof padding === "number") {
        console.log(Array(padding + 1).join("2"));
        return Array(padding + 1).join("1") + value;
    }
    if (typeof padding === "string") {
        return padding + value;
    }
    throw new Error("Expected string or number, got '".concat(typeof padding, "'."));
}
var aTo1 = padLeft("Hello", 4);
console.log(aTo1);
// 编译时通过但是运行时失败。
// let aTo2:string = padLeft("Hello World",true) //期望的字符串或数字，得到“布尔值”。
// console.log(aTo2);
function padLeftTo1(value, padding) {
    if (typeof padding === "number") {
        console.log(Array(padding + 1).join("2"));
        return Array(padding + 1).join("1") + value;
    }
    if (typeof padding === "string") {
        return padding + value;
    }
    throw new Error("Expected string or number, got '".concat(typeof padding, "'."));
}
function logger(state) {
    switch (state.state) {
        case "loading":
            return "Downloading...";
        case "failed":
            return "Error ".concat(state.code, " downloading");
        case "success":
            return "Downloaded ".concat(state.response.title, "---").concat(state.response.summary);
        default:
            return "string";
    }
}
var log = logger({ state: "loading" });
console.log(log);
function assertNever(x) {
    throw new Error("Unexpected object: " + x);
}
function loggerTo1(s) {
    switch (s.state) {
        case "loading":
            return "loading request";
        case "failed":
            return "failed with code ".concat(s.code);
        case "success":
            return "got response";
        // case "from_cache":
        //   return "got response";
        default:
            return assertNever(s);
    }
}
var handleArtistsResponse = function (response) {
    if (response.error) {
        console.error(response.error.message);
        return;
    }
    console.log(response.artists);
};
